package com.xy.entity.order;

import com.alibaba.fastjson.annotation.JSONField;
import com.xy.common.jpa.AbstractTimestampEntity;
import com.xy.entity.msg.ActivityMsg;
import com.xy.entity.msg.OrderMsg;
import com.xy.entity.msg.ProductMsg;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Thinkpad on 2018/1/17.
 */

@Entity
@Data
@Table(name = "order_main")
@EqualsAndHashCode(exclude ={"orderPostponeSet","orderDelivery","orderMsgs","productMsgs"})
public class OrderMain extends AbstractTimestampEntity {

    private String userId ;//用户ID

    private String orderNo ;//订单编号

    private String boxNo ;//箱子编号

    private BigDecimal productMoney;//商品总金额

    private BigDecimal productPayMoney;//商品应付金额

    private BigDecimal productPledgeMoney;//商品押金

    private String productWeight;//商品总重量

    private BigDecimal freightType;//订单运费

    private BigDecimal freeMoney;//订单优惠

    private String discountId;//优惠卷id

    private BigDecimal payMoney;//应付金额

    private String payType;//支付方式

    private String payCode; //网上支付code

    private String payName; //网上支付名称

    private String payStatus; //支付状态

    private String payAt; //支付时间

    private String orderStatus; //订单状态

    private String orderAt; //下单时间

    private Date deliveryTime; //配送时间

    private String postponeFlag; //是否延期

    private String postponeTime; //延期日期

    private String deliveryStatus; //发货状态

    private String deliveryAt; //发货时间

    private String getStatus; //收货状态

    private String getAt; //收货时间

    private String note; //订单附言

    private String mark; //订单备注

    private String delFlag; //是否删除

    @OneToOne(mappedBy = "orderMain", fetch = FetchType.EAGER)
    @JSONField(serialize = false)
    private OrderDelivery orderDelivery;

    @ManyToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @OrderBy("opsAt ASC")
    private Set<OrderPostpone> orderPostponeSet = new HashSet<OrderPostpone>();


    @OneToMany(mappedBy = "orderMain", cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    private Set<OrderMsg> orderMsgs = new HashSet<>();

    @OneToMany(mappedBy = "orderMain", cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    private Set<ProductMsg> productMsgs = new HashSet<>();

}
